from jiekou.port_job.mall.interface.Interface import Memberlnterface
from jiekou.port_job.mall.utils.sendmethod import SendMethod


class CartInterface:
    def __init__(self,url,headers):
        self.url = url
        self.headers = headers
    def cart_add(self, payload):
        method = 'post'
        url = self.url + '/cart/add'

        return SendMethod.send_method(method=method, url=url, json=payload, headers=self.headers)
if __name__ == '__main__':
    url = "http://47.108.206.100:8085"
    payload = {
        "username": "Jerry5",
        "password": "123456789"}

    headers = Memberlnterface(url).get_member_token(payload)
    print(headers)
    cart = CartInterface(url, headers)
    payload = {
        "createDate": "2022-06-10T04:01:35.734Z",
        "deleteStatus": 0,
        "id": 0,
        "memberId": 1828,
        "memberNickname": "Jerry5",
        "modifyDate": "2022-06-10T04:01:35.734Z",
        "price": 2699.00,
        "productAttr": '[{"key":"颜色","value":"黑色"},{"key":"容量","value":"32G"}]',
        "productBrand": "小米",
        "productCategoryId": 19,
        "productId": 27,
        "productName": "小米8 全面屏游戏智能手机 6GB+64GB 黑色 全网通4G 双卡双待",
        "productPic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180615/xiaomi.jpg",
        "productSkuCode": "201808270027001",
        "productSkuId": 98,
        "productSn": "7437788",
        "productSubTitle": "骁龙845处理器，红外人脸解锁，AI变焦双摄，AI语音助手小米6X低至1299，点击抢购",
        "quantity": 1
    }
    print(cart.cart_add(payload))  # 调用添加购物车


